package year2022.leetcode.simple;

public class CanConstruct {

    public static void main(String[] args){
        CanConstruct c = new CanConstruct();
        boolean flag = c.canConstruct("sasfda", "fjagsgdesa");
        System.out.println(flag);
    }

    public boolean canConstruct(String ransomNote, String magazine) {
        char[] chars = ransomNote.toCharArray();
        for (char c : chars) {
            String s = String.valueOf(c);
            if (magazine.contains(s)){
                magazine = magazine.replaceFirst(s, "");
            } else {
                return false;
            }
        }
        return true;
    }

}
